package com.jack.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class tes {

    public static int[][] reconstructQueue(int[][] people){
        if(people == null){
            return null;
        }
        Arrays.sort(people, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0] == o2[0] ? o1[1] - o2[1] : o2[0] - o1[0];
            }
        });
        List<int[]> result = new ArrayList<>();
        for (int[] person : people) {
            result.add(person[1], person);
        }
        return result.toArray(new int[people.length][2]);
    }

    public static class Num{
        int i = 1;
        boolean flag = false;
    }

    public class PrintQi implements Runnable{
        Num num;
        PrintQi(Num num){
            this.num = num;
        }
        @Override
        public void run() {
            while(num.i <= 100){
                synchronized (num){
                    if(num.flag){
                        try {
                            num.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else{
                        System.out.println("奇数" + num.i);
                        num.i++;
                        num.flag = true;
                        num.notify();
                    }
                }
            }
        }
    }

    public class PrintOu implements Runnable{
        Num num;
        PrintOu(Num num){
            this.num = num;
        }
        @Override
        public void run() {
            while(num.i <= 100){
                synchronized (num){
                    if(!num.flag){
                        try {
                            num.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else{
                        System.out.println("偶数" + num.i);
                        num.i++;
                        num.flag = false;
                        num.notify();
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        int[][] people = {{7,0}, {4,4}, {7,1}, {5,0}, {6,1}, {5,2}};
        reconstructQueue(people);
    }
}
